<?php
/**
* function cart
* helper yang berfungsi untuk mengandle proses shoping cart
*/
function myCart()
{
	
	$ci=& get_instance();
	$sesId = $ci->session->userdata('session_id');
	$sql =$ci->db->query("SELECT SUM(temp_jml) as tot_temp,SUM(temp_subtotal) as tot_subtotal
							FROM tb_temp_cart
							WHERE session_id = '$sesId'");
	if ($sql->row('tot_temp')!=NULL && $sql->row('tot_subtotal')!=NULL):
		$tot_temp=$sql->row('tot_temp');
		$tot_subtotal=$sql->row('tot_subtotal');
	else:
		$tot_temp='0';
		$tot_subtotal='0';
	endif;
	
	
	$out_temp = '<a href="#view_cart" rel="facebox" title="Your Cart"><strong>Your Cart : </a><br>
                  '.$tot_temp.' items | <span class="red"> '.formatHarga($tot_subtotal,'lengkap').'</strong>';
	return $out_temp;
}

// VIEW CART JQUERY

function viewCart(){

	$ci=& get_instance();
	
	$session_id = $ci->session->userdata('session_id');
	$num_cart = $ci->Order_model->getCart($session_id,FALSE,TRUE);
	$cart = $ci->Order_model->getCart($session_id);
	$ses_id = $ci->session->userdata('session_id');
	$sql =$ci->db->query("SELECT SUM(temp_jml) as tot_temp,SUM(temp_subtotal) as tot_subtotal
								FROM tb_temp_cart
								WHERE session_id = '$session_id'");
	$cumb = anchor('home','<strong>Home</strong>').' &raquo; Keranjang Belanja';	
	$total= $sql->row('tot_subtotal');

	if($num_cart!=0):
	
	$output = '<table width="1" border="0" cellpadding="0">';

	$output .= '<thead>';

	$output .= '<th>Name</th>';
	$output .= '<th>Price</th>';
	$output .= '<th>Size</th>';
	$output .= '<th>Qty</th>';
	$output .= '<th>Payment</th>';
	
	$output .= '</thead>';
	foreach($cart as $cart):
		$output .= '<tr>';
		
		$output .= '<td>'.$cart['product'][0]['nama_produk'].'</td>';
		if($cart['persen_diskon'] != 0):
			$output .= '<td style="text-align:right;">'.formatHarga(getPriceDiskon($cart['harga'],$cart['persen_diskon']), 'lengkap').'</td>';
		else:
			$output .= '<td style="text-align:right;">'.formatHarga($cart['harga'], 'lengkap').'</td>';
		endif;
		
		$output .= '<td style="text-align:center;">'.getSize($cart['ms_size_id']).'</td>';
		$output .= '<td style="text-align:center;">'.$cart['temp_jml'].'</td>';
		$output .= '<td style="text-align:right;">'.formatHarga($cart['temp_subtotal'], 'lengkap').'</td>';
		$output .= '<td style="text-align:center;">';
		$output .= '</td>';
		$output .= '</tr>';
	endforeach;
		$output .= '<tr>';
		$output .= '<td colspan="4" class="cart_total"><span class="red"> TOTAL: </span></td>';
		$output .= '<td style="background-color:#CCC;text-align:right;"><strong>'.formatHarga($total,'lengkap').'</strong></td>';               
		$output .= '</tr>'  ;
		$output .= '</table>';

	else:
		$output = '<table class="cart_table">';
		$output .= '- Data kosong -';
		$output .= '</table>';
	endif;
	
	return $output;

}

function tempCart()
{
	$ci=& get_instance();
	$sesId = $ci->session->userdata('session_id');
	
	$ci->db->where('session_id',$sesId);
	$query = $ci->db->get('tb_temp_cart');
	$custLog = $query->result_array();
	$num_cart = $query->num_rows();
		//jika cust ada sesuai session
		if($num_cart>0):
			$temp=$num_cart;
		else:
			$temp=0;
		endif;
	return $temp;
}

/**
* function templogin
* helper yang berfungsi menyimpan log member yg telah login
*/

function memLogin()
{
	$ci=& get_instance();
	$sesId = $ci->session->userdata('session_id');
	
	$ci->db->where('session_id',$sesId);
	$ci->db->join('tb_member','tb_member.member_id = tb_temp_login.temp_mem_id');
	$query = $ci->db->get('tb_temp_login');
	$custLog = $query->result_array();
	$num_cart = $query->num_rows();
		//jika cust ada sesuai session
		if($num_cart>0):
			$log=$num_cart;
		else:
			$log=0;
		endif;
	return $log;
}

/**
* function dropdown
* helper untuk handle semua form dropdown
*/
function produkKatDropdown($selected=FALSE,$parent=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();
    $ci->load->Model('Produk_model');
	if($parent!=''):
		$ret = $ci->db->where('parent_kat_id',$parent)
				->order_by('parent_kat_id','asc')
				->get('tb_kat_produk')->result();
		$attr = 'id="prod_kat_id" class="title"';
		$options = array(
				  '' => ' - Select - '
				  );
		foreach($ret as $row):
			$ret_options = array(
				  $row->kategori_id => $row->nama_kategori,
				);
			$options = array_merge($options,$ret_options);
		endforeach;
		$output = form_dropdown('prod_kat_id', $options, '', $attr);
	else:
		$res = $ci->Produk_model->getKatProduk('all',FALSE,FALSE,FALSE);
		$output = "<select id='prod_kat_id' name='prod_kat_id' class='title'>";
			$output .= "<option value=''> - Select - </option>";
			foreach($res as $row):
				if($selected):
					if($row["kategori_id"]==$selected):
						$output .= "<option value='".$row["kategori_id"]."' selected='selected'>".$row['nama_kategori']."</option>";
					else:
						$output .= "<option value='".$row["kategori_id"]."'>".$row['nama_kategori']."</option>";
					endif;
				else:
					$output .= "<option value='".$row["kategori_id"]."'>".$row['nama_kategori']."</option>";
			   endif;
			endforeach;
		$output .= "</select>";
	endif;
    return $output;
}

function dropdown_kat($brand_id,$parent=FALSE,$selected=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();
	if($parent):
		$category = $ci->db->where('kategori_parent_kategori_id',$parent)
			->where('kategori_brand_id',$brand_id)
			->where('kategori_level',$level)
			->get('tb_kategori')->result();
	endif;
	$category = $ci->db->where('kategori_brand_id',$brand_id)
		->get('tb_kategori')->result();
	$output = '';
	$output .= "<option value=''> - Select - </option>";
	foreach($category as $row):
		if($selected):
			if($row->kategori_id==$selected):
				$output .= "<option value='".$row->kategori_id."' selected='selected'>".$row->kategori_nama."</option>";
			else:
				$output .= "<option value='".$row->kategori_id."'>".$row->kategori_nama."</option>";
			endif;
		else:
			$output .= "<option value='".$row->kategori_id."'>".$row->kategori_nama."</option>";
	   endif;
	endforeach;
	return $output;
}

function getSize($ms_size_id)
{
	$ci=& get_instance();
    $ci->db->where('ms_size_id',$ms_size_id);
    $row = $ci->db->get('tb_ms_size')->row();
	$size = $row->kode_size;
    return $size;
}

function jenkelDropdown($selected)
{
	$class = 'class="contact_input"';
	$options = array(
				  '' => '- Select -',
                  'Male'=> 'Male',
                  'Female' => 'Female'
                );
	return form_dropdown('jenkel',$options,$selected,$class);
} 


function shortDropdown($key)
{
    $ajax_event = 'class="contact_input" onChange="show_sort(this.value)"';
	$options = array(
		  '' => '- Select -',
                  '1'=> 'Price Range',
                  '2' => 'Shopping Program',
                  '3' => 'Collection',
                );
	return form_dropdown('short',$options,$key,$ajax_event);
} 

function sizeDropdown($selected=FALSE,$id_prod=FALSE)
{
	$ci=& get_instance();
    $ci->db->join('tb_ms_size','tb_ms_size.ms_size_id = tb_size_produk.ms_size_id');
    $ci->db->where('tb_size_produk.produk_id',$id_prod);
    $arr_size = $ci->db->get('tb_size_produk')->result_array();

    $output = "<select id='size_produk_id' name='size_produk_id' class='title'>";
		foreach($arr_size as $row):
		    if($selected):
		    	if($row["ms_size_id"]==$selected):
					$output .= "<option value='".$row["ms_size_id"]."' selected='selected'>".$row['kode_size']."</option>";
				else:
					$output .= "<option value='".$row["ms_size_id"]."'>".$row['kode_size']."</option>";
				endif;
		    else:
		    	$output .= "<option value='".$row["ms_size_id"]."'>".$row['kode_size']."</option>";
		   endif;
		endforeach;
	$output .= "</select>";
    return $output;
}  

// tanggalan

function getTh($ket,$var)
{
	if($ket == 'plus'):
		$dt = explode('-',date('Y-m-d'));
		$th = $dt[0] + $var;
	elseif($ket == 'min'):
		$dt = explode('-',date('Y-m-d'));
		$th = $dt[0] - $var;
	endif;
	return $th;
}

function dateDropdown($name,$date=FALSE,$th_st=FALSE,$th_end=FALSE)
{
	$ci=& get_instance();
	if($date){
	$dt = explode('-',$date);
	$year = $dt[0];
	$mon = $dt[1];
	$day = $dt[2];
	}
	
	$ret = '<select class="sel_input" name="'.$name.'_d"  style="width:50px;">';
	for ($i=1;$i<32;$i++):
		$val=$i;
		if($val < 10):
			$val = '0'.$val;
		endif;
		if ($date):
			if($val == $day):
				$ret .= '<option value="'.$val.'" selected="selected">'.$i.'</option>';
			else:
				$ret .= '<option value="'.$val.'">'.$i.'</option>';
			endif;
		else:
			$ret .= '<option value="'.$val.'">'.$i.'</option>';
		endif;
	endfor;
	$ret .='</select> ';

	$month = array	('Jan','Feb','Mar','Apr','Mei','Jun','Jul','Ags','Sep','Okt','Nov','Des');
	$ret .= '<select class="sel_input" name="'.$name.'_m"  style="width:60px;">';
	for ($i=0;$i<12;$i++):
		$val=$i+1;
		if($val < 10):
			$val = '0'.$val;
		endif;
		if ($date):
			if($val == $mon):
				$ret .= '<option value="'.$val.'" selected="selected">'.$month[$i].'</option>';
			else:
				$ret .= '<option value="'.$val.'">'.$month[$i].'</option>';
			endif;
		else:
			$ret .= '<option value="'.$val.'">'.$month[$i].'</option>';
		endif;
	endfor;
	$ret .='</select> ';
	

	$minyear = $th_st;
	$plusyear = $th_end;

	$ret .= '<select class="sel_input" name="'.$name.'_y" style="width:64px;">';
	for ($i=$minyear;$i<=$plusyear;$i++):
		if ($date):
			if($i==$year):
				$ret .= '<option value="'.$i.'" selected="selected">'.$i.'</option>';
			else:
				$ret .= '<option value="'.$i.'">'.$i.'</option>';
			endif;
		else:
			$ret .= '<option value="'.$i.'">'.$i.'</option>';
		endif;
	endfor;
	$ret .='</select>';
return $ret;

}


// Generate a random character string
function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')
{
    // Length of character list
    $chars_length = (strlen($chars) - 1);

    // Start our string
    $string = $chars{rand(0, $chars_length)};
    
    // Generate random string
    for ($i = 1; $i < $length; $i = strlen($string))
    {
        // Grab a random character from our list
        $r = $chars{rand(0, $chars_length)};
        
        // Make sure the same two characters don't appear next to each other
        if ($r != $string{$i - 1}) $string .=  $r;
    }
    
    // Return the string
    return $string;
}


function currentMenu(){
	
	$ci=& get_instance();
	
	$cur = 'current';
	return $cur;

}

function bulanDropdown($name,$date=FALSE,$th_st=FALSE,$th_end=FALSE)
{

	$ci=& get_instance();
	if($date){
	$dt = explode('-',$date);
	$year = $dt[0];
	$mon = $dt[1];
	$day = $dt[2];
	}
	
	
	$month = array	('Jan','Feb','Mar','Apr','Mei','Jun','Jul','Ags','Sep','Okt','Nov','Des');
	$ret = '<select class="sel_input" name="'.$name.'_m"  style="width:60px;">';
	for ($i=0;$i<12;$i++):
		$val=$i+1;
		if($val < 10):
			$val = '0'.$val;
		endif;
		if ($date):
			if($val == $mon):
				$ret .= '<option value="'.$val.'" selected="selected">'.$month[$i].'</option>';
			else:
				$ret .= '<option value="'.$val.'">'.$month[$i].'</option>';
			endif;
		else:
			$ret .= '<option value="'.$val.'">'.$month[$i].'</option>';
		endif;
	endfor;
	$ret .='</select> ';
	

	$minyear = $th_st;
	$plusyear = $th_end;

	$ret .= '<select class="sel_input" name="'.$name.'_y" style="width:64px;">';
	for ($i=$minyear;$i<=$plusyear;$i++):
		if ($date):
			if($i==$year):
				$ret .= '<option value="'.$i.'" selected="selected">'.$i.'</option>';
			else:
				$ret .= '<option value="'.$i.'">'.$i.'</option>';
			endif;
		else:
			$ret .= '<option value="'.$i.'">'.$i.'</option>';
		endif;
	endfor;
	$ret .='</select>';
return $ret;

}


function statusMemberDropdown($selected)
{
	$options = array(
                  '1'=> 'Aktif',
				  '0'=> 'Block'
                );
	$class = 'class="search_input"';
	return form_dropdown('stat_mem',$options,$selected,$class);
} 
  


function kabDropdown($prov_id=FALSE,$kab_id=FALSE)
{
	$ci=& get_instance();
	$ci->db->where('prov_id',$prov_id);
	$kab = $ci->db->get('tb_kab')->result_array();
	
	$output = "<select id='kab_id' class='contact_input' name='kab_id'>";
			$output .= "<option value=''> - Select - </option>";
		    foreach($kab as $kab):
		    	if($kab_id):
		    		if($kab["kab_id"]==$kab_id):
						$output .= "<option value='".$kab["kab_id"]."' selected='selected'>".$kab['nama_kabupaten']."</option>";
					else:
						$output .= "<option value='".$kab["kab_id"]."'>".$kab['nama_kabupaten']."</option>";
					endif;
		    	else:
		    		$output .= "<option value='".$kab["kab_id"]."'>".$kab['nama_kabupaten']."</option>";
		    	endif;
		    endforeach;
	$output .= "</select>";
	return $output;
}

function provDropdown($selected=FALSE)
{
	$ci=& get_instance();
	$ci->db->select('prov_id,nama_provinsi');
	$row = $ci->db->get('tb_province')->result_array();
    	$output = "<select id='prov_id' class='contact_input' name='prov_id' onChange='showKab(this.value)'>";
			$output .= "<option value=''> - Select - </option>";
		    foreach($row as $row):
		    	if($selected):
		    		if($row["prov_id"]==$selected):
						$output .= "<option value='".$row["prov_id"]."' selected='selected'>".$row['nama_provinsi']."</option>";
					else:
						$output .= "<option value='".$row["prov_id"]."'>".$row['nama_provinsi']."</option>";
					endif;
		    	else:
		    		$output .= "<option value='".$row["prov_id"]."'>".$row['nama_provinsi']."</option>";
		    	endif;
		    endforeach;
	    $output .= "</select>";
    return $output;
}


function persen_diskonDropdown()
{
	$ci=& get_instance();
	$id = $ci->uri->segment(4);
	
	if($id!=''):
		$row = $ci->Produk_model->getProductById($id);
		$disk = $row->persen_diskon;
	else:
		$disk = 0;
	endif;
	
	$ret = "<select id='persen_diskon' name='persen_diskon'>";
	for ($i=0;$i<=10;$i++):
		$val=$i*1;
		if($val == $disk):
			$val = $disk;
			$ret .= '<option value="'.$val.'" selected="selected">'.$val.'</option>';
		else:
			$ret .= '<option value="'.$val.'">'.$val.'</option>';
		endif;
	endfor;
	$ret .='</select> ';
	return $ret;
}


function kontenDropdown($selected)
{
	$options = array(
                  'tentang-kami'=> 'Tentang Kami',
                  'terms' => 'Terms and Condition',
				  'terms-order' => 'Terms and Condition Order',
				  'cara-transaksi' => 'Cara Transaksi',
                  'faq' => 'FAQ'
                );
	return form_dropdown('page',$options,$selected);
}

function ruleDropdown($selected)
{
	$options = array(
                  'Manager'=> 'Manager',
                  'Administrator' => 'Administrator',
				  'Sales' => 'Sales',
                );
	return form_dropdown('user_rule',$options,$selected);
}

function dropDownBank($selected=FALSE)
{
		$ci=& get_instance();
		$row = $ci->db->get('tb_bank')->result_array();
		$output = "<select id='bank_id' class='contact_input' style='width:260px' name='bank_id'>";
		foreach($row as $row):
			if($selected):
				if($row["bank_id"]==$selected):
						$output .= "<option value='".$row["bank_id"]."' selected='selected'>".$row['nama_rek']." - ".$row['nama_bank']." - ".$row['no_rek']."</option>";
					else:
						$output .= "<option value='".$row["bank_id"]."'>".$row['nama_rek']." - ".$row['nama_bank']." - ".$row['no_rek']."</option>";
					endif;
		    	else:
					$output .= "<option value='".$row["bank_id"]."'>".$row['nama_rek']." - ".$row['nama_bank']." - ".$row['no_rek']."</option>";
			endif;
		endforeach;
		$output .= "</select>";
		return $output;
}

function dropDownLogistic($selected=FALSE){
		$ci=& get_instance();
		$row = $ci->db->get('tb_logistik')->result_array();
		$output = "<select id='logistik_id' class='contact_input' name='logistik_id'>";
		foreach($row as $row):
			if($selected):
				if($row["logistik_id"]==$selected):
						$output .= "<option value='".$row["logistik_id"]."' selected='selected'>".$row['log_nama']."</option>";
					else:
						$output .= "<option value='".$row["logistik_id"]."'>".$row['log_nama']."</option>";
					endif;
		    	else:
					$output .= "<option value='".$row["logistik_id"]."'>".$row['log_nama']."</option>";
			endif;
		endforeach;
		$output .= "</select>";
		return $output;
}

function dropDownLogisticGroup($selected=FALSE){
		$ci=& get_instance();
		$ci->db->group_by('log_nama');
		$row = $ci->db->get('tb_logistik')->result_array();
		$output = "<select id='log_nama' class='contact_input' name='log_nama'>";
		foreach($row as $row):
			if($selected):
				$ci->db->where('logistik_id',$selected);
				$row2 = $ci->db->get('tb_logistik')->row();
				if($row["log_nama"]==$row2->log_nama):
						$output .= "<option value='".$row["log_nama"]."' selected='selected'>".$row['log_nama']."</option>";
					else:
						$output .= "<option value='".$row["log_nama"]."'>".$row['log_nama']."</option>";
					endif;
		    	else:
					$output .= "<option value='".$row["log_nama"]."'>".$row['log_nama']."</option>";
			endif;
		endforeach;
		$output .= "</select>";
		return $output;
}

function showLogistic($selected=FALSE){
		$ci=& get_instance();
		$ci->db->group_by('log_nama');
		$row = $ci->db->get('tb_logistik')->result_array();
		foreach($row as $row):
			echo ' <a class="white_back" href="#log'.$row['log_nama'].'" rel="facebox">'.$row['log_nama'].'</a> ';
			$ci=& get_instance();
			$ci->db->where('log_nama',$row['log_nama']);
			$ci->db->join('tb_province','prov_id = log_prov_id','left');
			$ci->db->join('tb_kab','kab_id = log_kab_id','left');
			$ci->db->order_by('tb_province.prov_id');
			$res2 = $ci->db->get('tb_logistik')->result_array();
			echo '<div id="log'.$row['log_nama'].'" style="display:none">';
			echo '<strong>'.$row['log_nama'].'</strong><br />';
			echo '<table border="0" cellpadding="0" cellspacing="0" class="shoppingTable">';
				echo '<tr class="cart_title">';
					echo '<td>Pilih</td>';
					echo '<td>Kode</td>';
					echo '<td>Propinsi</td>';
					echo '<td>Kabupaten</td>';
					echo '<td>Biaya</td>';
					foreach($res2 as $row2):
					echo '<tr>';
							echo '<td class=""><input type="radio" name="radio" id="radio" value="'.$row2['log_nama'].'-'.$row2['logistik_id'].'" onClick="insertLog(this.value)"/></td>';
							echo '<td class="isi_tab">'.$row2['log_nama'].'-'.$row2['logistik_id'].'</td>';
							echo '<td class="isi_tab">'.$row2['nama_provinsi'].'</td>';
							echo '<td class="isi_tab">'.$row2['nama_kabupaten'].'</td>';
							echo '<td class="isi_tab_numb">'.formatHarga($row2['log_biaya'],'lengkap').'</td>';	
					echo '</tr>';
				endforeach;
			echo '</table>';
			echo '</div>';
			
		endforeach;

}

function dropDownOrderStatus($selected){
	$options = array(
				  ''=> '- Select -',
                  'neworder'=> 'New Order',
                  'confirmed' => 'Confrimed',
                  'pending' => 'Pending',
                  'shipped' => 'Shipped',
                  'closed'=>'Closed'
                );
	return form_dropdown('status', $options, $selected);
}

/**
* function getberita
* fungsi sidebar berita
*/

function getBerita()
{
	$ci=& get_instance();
	$ci->db->where('page','ticker');
	$ci->db->where('published','y');
	$ci->db->limit(3);
	$ci->db->order_by('konten_id','desc');
	$query = $ci->db->get('tb_konten');
	$res = $query->result_array();
	
	$i=1;
	foreach($res as $row):
		echo '<div class="news_list">';
			echo '<div class="news_title_list"><a href="#">'.$row['judul'].'</a></div>';
			echo '<strong>'.formatDate($row['date'],'short').'</strong>';
			echo character_limiter($row['isi_konten'],200);
			echo '<a href="#news'.$i.'" rel="facebox">more</a>';
		echo '</div>';
		
		echo '<div id="news'.$i.'" style="display:none">';
		echo '<strong>'.$row['judul'].'</strong><br />';
		echo '<strong>'.formatDate($row['date'],'short').'</strong><br />';
		echo $row['isi_konten'];
		echo '</div>';
	$i++;
	endforeach;
	echo '<a href='.site_url().'/konten/archive>Archive</a>';
	echo '<br /><br />';
	
	
}

/**
* function getterms
* fungsi sidebar berita
*/
function getTerms($terms=FALSE)
{
	$ci=& get_instance();
	$ci->db->where('page',$terms);
	$query = $ci->db->get('tb_konten');
	$row = $query->row();
	
	echo '<div id="info" style="display:none">';
	echo '<strong>'.$row->judul.'</strong>';
	echo $row->isi_konten;
	echo '</div>';

}

function getOrderAccount($mem_id)
{
	$ci=& get_instance();
	$res = $ci->Order_model->getOrderById('member_id',FALSE,$mem_id);
	
	foreach($res as $row3):;
		echo '<div id="order'.$row3['order_id'].'" style="display:none;">';
			$ci=& get_instance();
			$res2= $ci->Order_model->getOrderById('all_where_mem_id',$row3['order_id'],FALSE);
			echo '<p>Order Detail <strong>'.$row3['order_code'].'</strong> at <strong>'.formatDate($row3['order_date'],'short1').'</strong><p>';
			echo '<table width="1" border="0" cellpadding="0">';
				echo '<thead>';
					echo '<th>Item</th>';
					echo '<th>Price</th>';
					echo '<th>Qty</th>';
					echo '<th>Sub Total</th>';
						
					echo '</thead>';
				foreach($res2 as $row2):
						echo '<tr>';
							echo '<td class="isi_tab">'.$row2['nama_produk'].'</td>';
							echo '<td class="isi_tab_numb">'.formatHarga($row2['harga'],'lengkap').'</td>';
							echo '<td class="isi_tab_numb">'.$row2['det_jml'].'</td>';
							echo '<td class="isi_tab_numb">'.formatHarga($row2['det_subtotal'],'lengkap').'</td>';
						echo '</tr>';
				endforeach;
						echo '</tr>';
							
							if($row3['order_logistik_kirim_id'] !=0):
								echo '<td class="isi_tab">Delivery Service : Logistic Name </td>';
								echo '<td class="isi_tab"></td>';
								echo '<td class="isi_tab"></td>';
								echo '<td class="isi_tab_numb">'.formatHarga($row3['biaya_logistik'],'lengkap').'</td>';
							else:
								echo '<td class="isi_tab">Delivery Service : - </td>';
								echo '<td class="isi_tab"></td>';
								echo '<td class="isi_tab"></td>';
								echo '<td class="isi_tab_numb"> - </td>';
							endif;
							
						echo '<tr>';
						echo '</tr>';
							echo '<td class="isi_tab">GRAND TOTAL</td>';
							echo '<td class="isi_tab"></td>';
							echo '<td class="isi_tab"></td>';
							echo '<td class="isi_tab_numb"><strong>'.formatHarga($row3['total'],'lengkap').'</strong></td>';
						echo '<tr>';
			echo '</table>';
			echo '<p>Payment : <strong>'.$row3['nama_bank'].'</strong> - <strong>'.$row3['nama_rek'].'</strong> No Rek : <strong>'.$row3['no_rek'].'</strong><p>';
			// echo '<p>NB : Harga dan biaya dapat berubah sewaktu - waktu tanpa pemberitahuan. Jumlah Sub Total dan Grand Total menggunakan harga dan biaya saat terjadi transaksi</p>';
			echo '</div>';
	endforeach;
}

/**
* function boolean
* helper untuk handle form dengan fungsi boolean ya/tidak, ada/tidak dal lain lain
*/

function booleanValueAva($value,$name)
{
	if($value=='Ya'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="Ya" checked="checked"><label class="span" for="'.$name.'_y">Ya</label>&nbsp;&nbsp;';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="Tidak"><label class="span" for="'.$name.'_n">Tidak</label>';
	elseif($value=='Tidak'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="Ya"><label class="span" for="'.$name.'_y">Ya</label>&nbsp;&nbsp;';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="Tidak" checked="checked"><label class="span" for="'.$name.'_n">Tidak</label>';
	endif;
	return $output;
}

function booleanValuePromo($value,$name)
{
	if($value=='Ya'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="Ya" checked="checked"><label class="span" for="'.$name.'_y">Ya</label>&nbsp;&nbsp;';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="Tidak"><label class="span" for="'.$name.'_n">Tidak</label>';
	elseif($value=='Tidak'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="Ya"><label class="span" for="'.$name.'_y">Ya</label>&nbsp;&nbsp;';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="Tidak" checked="checked"><label class="span" for="'.$name.'_n">Tidak</label>';
	endif;
	return $output;
}

function booleanValuePublish($value,$name)
{
	if($value=='Ya'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="Ya" checked="checked"><label class="span" for="'.$name.'_y">Ya</label>&nbsp;&nbsp;';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="Tidak"><label class="span" for="'.$name.'_n">Tidak</label>';
	elseif($value=='Tidak'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="Ya"><label class="span" for="'.$name.'_y">Ya</label>&nbsp;&nbsp;';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="Tidak" checked="checked"><label class="span" for="'.$name.'_n">Tidak</label>';
	endif;
	return $output;
}

function booleanValueStatus($value,$name)
{
	if($value=='y'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="y" checked="checked"><label class="span" for="'.$name.'_y">Ditampilkan</label><br>';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="n"><label class="span" for="'.$name.'_n">Tidak Ditampilkan</label>';
	elseif($value=='n'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="y"><label class="span" for="'.$name.'_y">Ditampilkan</label><br>';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="n" checked="checked"><label class="span" for="'.$name.'_n">Tidak Ditampilkan</label><br>';
	endif;
	return $output;
}

function booleanValueEnable($value,$name)
{
	if($value=='enable'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="enable" checked="checked"><label class="span" for="'.$name.'_y">Enable</label>&nbsp;&nbsp;';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="disable"><label class="span" for="'.$name.'_n">Disable</label>';
	elseif($value=='disable'):
		$output = '<input type="radio" id="'.$name.'_y" name="'.$name.'" value="enable"><label class="span" for="'.$name.'_y">Enable</label>&nbsp;&nbsp;';
		$output .= '<input type="radio" id="'.$name.'_n" name="'.$name.'" value="disable" checked="checked"><label class="span" for="'.$name.'_n">Disable</label><br>';
	endif;
	return $output;
}

/**
* fungsi-fungsi bantuan 
*/
function listKategori()
{
	$ci=& get_instance();
    $ci->load->Model('Produk_model');
    $res = $ci->Produk_model->getKatProduk('all',FALSE,FALSE,FALSE);
	
	$output = "<ul class='list'>";
		foreach($res as $row):
			$output .= "<li>".anchor('kategori/all/'.makeslug($row['nama_kategori']).'/'.$row['kategori_id'],$row['nama_kategori'])."</li>";
		endforeach;
	$output .= "</ul>";
    return $output;                                       				
}

function alias($string)
{
	$ci=& get_instance();
	return strtolower(url_title($string));
}

function getProdukDetail($id)
{
	$ci=& get_instance();
	$ci->db->where('produk_id',$id);
	return $ci->db->get('tb_produk')->row();
}

function getProductCatDetail($kategori_id)
{
	$ci=& get_instance();
	return $ci->db->where('kategori_id',$kategori_id)
			->get('tb_kat_produk')
			->row();
}

/**
* function loadTinyMCE
* @uses loadTinyMCE($theme) $theme = advance, simple
* @filesource application/helpers/ies_helper.php
*/
function loadTinyMCE($ret='name')
{
	if($ret == 'simple'):
		$output = '
		<script type="text/javascript" src="'.base_url().'assets/js/tiny_mce/tiny_mce.js"></script>
		<script type="text/javascript">
		tinyMCE.init({
			// General options
			mode : "specific_textareas",
			editor_selector : "mceEditor",

			theme : "advanced",
			plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,|,undo,redo,|,bullist,numlist,outdent,indent,blockquote,|,link,unlink,|,pastetext,pasteword,|,preview",
			theme_advanced_buttons2 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,media,advhr,|,fullscreen",
			theme_advanced_buttons3 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,
			theme_advanced_resize_horizontal : false,

			// Example content CSS (should be your site CSS)
			content_css : "'. base_url().'assets/js/tiny_mce/css/content.css",

		})
		</script>
		';
	elseif($ret=='medium'):
		$output = '
		<script type="text/javascript" src="'.base_url().'assets/js/tiny_mce/tiny_mce.js"></script>
			<script type="text/javascript">
				tinyMCE.init({
					// General options
					mode : "specific_textareas",
					editor_selector : "mceEditor",
					relative_urls : false,
					remove_script_host : false,
					document_base_url : "'.base_url().'",

					theme : "advanced",
					plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

					// Theme options
					theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,|,cut,copy,paste,pastetext,pasteword",
					theme_advanced_buttons2 : "search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code",
					theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,media,advhr,|,fullscreen",
					theme_advanced_buttons4 : "cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,insertdate,inserttime,preview,|,forecolor,backcolor",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					theme_advanced_statusbar_location : "bottom",
					theme_advanced_resizing : true,
					theme_advanced_resize_horizontal : false,

					// Example content CSS (should be your site CSS)
					content_css : "'. base_url().'assets/js/tiny_mce/css/content.css",

					// Drop lists for link/image/media/template dialogs
					template_external_list_url : "lists/template_list.js",
					external_link_list_url : "lists/link_list.js",
					external_image_list_url : "lists/image_list.js",
					media_external_list_url : "lists/media_list.js",

				});
			</script>
		';
	elseif($ret=='advance'):
		$output = '
		<script type="text/javascript" src="'.base_url().'assets/js/tiny_mce/tiny_mce.js"></script>
			<script type="text/javascript">
				tinyMCE.init({
					// General options
					mode : "specific_textareas",
					editor_selector : "mceEditor",

					theme : "advanced",
					plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

					// Theme options
					theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
					theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code",
					theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,fullscreen",
					theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,insertdate,inserttime,preview,|,forecolor,backcolor",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					theme_advanced_statusbar_location : "bottom",
					theme_advanced_resizing : true,
					theme_advanced_resize_horizontal : false,

					// Example content CSS (should be your site CSS)
					content_css : "'. base_url().'assets/js/tiny_mce/css/content.css",

					// Drop lists for link/image/media/template dialogs
					template_external_list_url : "lists/template_list.js",
					external_link_list_url : "lists/link_list.js",
					external_image_list_url : "lists/image_list.js",
					media_external_list_url : "lists/media_list.js",

					// Style formats
					style_formats : [
						{title : "Bold text", inline : "b"},
						{title : "Red text", inline : "span", styles : {color : "#ff0000"}},
						{title : "Red header", block : "h1", styles : {color : "#ff0000"}},
						{title : "Example 1", inline : "span", classes : "example1"},
						{title : "Example 2", inline : "span", classes : "example2"},
						{title : "Table styles"},
						{title : "Table row 1", selector : "tr", classes : "tablerow1"}
					],

					// Replace values for the template plugin
					template_replace_values : {
						username : "Some User",
						staffid : "991234"
					}
				});
			</script>
		';
	endif;
	echo $output;
}

/**
* function option
* helper untuk mengambil data dari tabel tb_option
*/

function getOption($name=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();

	$ci->db->select('option_name, option_value');
	$ci->db->where('option_name',$name);
	$ci->db->limit(1);
	$ret = $ci->db->get('tb_option')->row_array();

	$output = $ret['option_value'];
	return $output;
}



/**
* function show price after diskon
* 
*/
function getPriceDiskon($price,$disc)
{
	$dc_val = ($price * $disc) / 100;
	
	$new_price = $price - $dc_val;
	
	return $new_price;

}



/**
* function makeslug
* digunakan untuk mereplace spasi ketika akan ditampilkan di url address
*/

function makeslug($string)
{
	$slug= strtolower(preg_replace('/[^A-Za-z0-9-]+/', '-', $string));
	$slug = str_replace(" ", "-", $slug);
	return $slug;
}
/**
* function memformat harga
* digunakan membuat format rupiaah
*/

function formatHarga($n,$lengkap=FALSE) 
{
	// first strip any formatting;
	$n = (0+str_replace(",","",$n));

	// is ci a number?
	if(!is_numeric($n)) return false;

	if($lengkap)$n = number_format($n,0,",",".");
	// now filter it;
	else if($n>1000000000000) $n= number_format(round(($n/1000000000000),0,",","."),1).' trilyun';
	else if($n>1000000000) $n= number_format(round(($n/1000000000),0,",","."),1).' milyar';
	else if($n>1000000) $n= number_format(round(($n/1000000),1),0,",",".").' juta';
	else if($n>1000) $n= number_format(round(($n/1000),1),0,",",".").' ribu';

	return "Rp ".$n ;
}

/*
Fungsi convert tanggal ke tanggalan indonesia
*/
function indDate($date) 
{
	$arr_bulan = array("Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "Nopember", "Desember");
	$arr_date = explode("-", $date);
	$arr_date[1] = intval($arr_date[1]);
	$arr_date[2] = intval($arr_date[2]);
	return $arr_date[2].' '.$arr_bulan[$arr_date[1] - 1].' '.$arr_date[0];
}

/**
* function formatDate
* @uses mmemformat tanggal
*/
function formatDate($date, $format='name')
{
	$ci=& get_instance();

	if($format=='long'):
		$unix_date = human_to_unix($date);
		return date('l, jS F, Y - H:i:s',$unix_date);
	elseif($format=='medium1'):
		$unix_date = human_to_unix($date);
		return date('jS M, Y - H:i',$unix_date);
	elseif($format=='medium2'):
		$unix_date = human_to_unix($date);
		return date('jS F, Y',$unix_date);
	elseif($format=='short'):
		$unix_date = human_to_unix($date);
		return date('d-M-Y',$unix_date);
	elseif($format=='ampm'):
		$unix_date = human_to_unix($date);
		return date('d M Y g:ia',$unix_date);
	elseif($format=='short1'):
		$unix_date = human_to_unix($date);
		return date('d M Y - H:i:s',$unix_date);
	elseif($format=='rssdate'):
		$unix_date = human_to_unix($date);
		return date('D, j M Y H:i:s +0700',$unix_date);
	elseif($format=='sitemap_date'):
		$unix_date = human_to_unix($date);
		return date('Y-m-d',$unix_date);
	elseif($format=='admin_date'):
		$unix_date = human_to_unix($date);
		return date('d M Y',$unix_date);
	elseif($format=='cek'):
		$unix_date = human_to_unix($date);
		return date('Y-m-d',$unix_date);
	elseif($format=='year_only'):
		$unix_date = human_to_unix($date);
		return date('Y',$unix_date);
	elseif($format=='timespan'):
		$unix_date = human_to_unix($date);
		return timespan($unix_date,now());
	else:
		return false;
	endif;

}
/**
* function crop image
* @uses croping gambar agar lebih kecil, 
* menggunaklan lib dari ci -> GD2
*/

function cropImage($image,$size,$filename,$ext,$filepath)
{
	$ci =& get_instance();

	$image_size = getimagesize($image);
	$image_width = $image_size['0'];
	$image_height = $image_size['1'];

	$config['image_library'] = 'gd2';
	$config['source_image'] = $image;
	$config['new_image'] = $filename.'_'.$size.'x'.$size.$ext;
	$config['maintain_ratio'] = FALSE;
	if($image_width > $image_height):
		$config['height'] = $image_height;
		$config['width'] = $image_height;
	elseif($image_width < $image_height):
		$config['height'] = $image_width;
		$config['width'] = $image_width;
	else:
		$config['height'] = $image_width;
		$config['width'] = $image_width;
	endif;

	if($image_width > $image_height):
		$config['x_axis'] = (5/100)*$image_width;
		$config['y_axis'] = '0';
	elseif($image_width < $image_height):
		$config['x_axis'] = '0';
		$config['y_axis'] = (5/100)*$image_height;
	else:
		$config['x_axis'] = (5/100)*$image_width;
		$config['y_axis'] = '0';
	endif;
	$ci->image_lib->initialize($config);
	$ci->image_lib->crop();

	$ci->image_lib->clear();

	$config2['image_library'] = 'gd2';
	$config2['source_image'] = $filepath.$config['new_image'];
	$config2['maintain_ratio'] = TRUE;
	$config2['height'] = $size;
	$config2['width'] = $size;

	$ci->image_lib->initialize($config2);
	$ci->image_lib->resize();

	return $filename.'_150x150'.$ext;

}

/**
* function resize
* @uses merubah atau mengganti ukuran gambar
* menggunaklan lib dari ci -> GD2
*/

function resizeImage($image,$width,$height,$filename,$ext,$filepath)
{
	$ci =& get_instance();

	$config['image_library'] = 'gd2';
	$config['source_image'] = $image;
	$config['new_image'] = $filename.'_'.$width.'x'.$height.$ext;
	$config['maintain_ratio'] = TRUE;
	$config['height'] = $height;
	$config['width'] = $width;

	$ci->image_lib->initialize($config);
	$ci->image_lib->resize();

	$image_size = getimagesize($filepath.$config['new_image']);
	$image_width = $image_size['0'];
	$image_height = $image_size['1'];
	rename($filepath.$config['new_image'],$filepath.$filename.'_'.$image_width.'x'.$image_height.$ext);
	return $filename.'_'.$image_width.'x'.$image_height.$ext;
	$ci->image_lib->clear();
}

/* mengambil data spesifikasi produk */
function vendorDropdown($selected=FALSE,$show_all=FALSE)
{
	$ci =& get_instance();
	$row = $ci->db->get('tb_brand')->result_array();
		$output = "<select id='prod_brand_id' class='contact_input' name='prod_brand_id' onchange='brand_change()'  style='width:300px;'>";
		foreach($row as $row):
			if(!$show_all):
				$cekKatNum = $ci->db->where('brand_id',$row["brand_id"])->count_all_results('tb_kat_produk');
				if($cekKatNum>0):
					if($selected):
						if($row["brand_id"]==$selected):
								$output .= "<option value='".$row["brand_id"]."' selected='selected'>".$row['nama_brand']."</option>";
							else:
								$output .= "<option value='".$row["brand_id"]."'>".$row['nama_brand']."</option>";
							endif;
						else:
							$output .= "<option value='".$row["brand_id"]."'>".$row['nama_brand']."</option>";
					endif;
				endif;
			else:
				if($selected):
					if($row["brand_id"]==$selected):
							$output .= "<option value='".$row["brand_id"]."' selected='selected'>".$row['nama_brand']."</option>";
						else:
							$output .= "<option value='".$row["brand_id"]."'>".$row['nama_brand']."</option>";
						endif;
					else:
						$output .= "<option value='".$row["brand_id"]."'>".$row['nama_brand']."</option>";
				endif;
			endif;
		endforeach;
		$output .= "</select>";
		return $output;
}

function produk_category_dropdown($brand_id=FALSE,$parent=FALSE,$selected=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();
	if($parent==FALSE):
		$parent = '0';
	endif;
	$ci->db->where('parent_kat_id', $parent);
	$category = $ci->db->where('brand_id', $brand_id)
			->get('tb_kat_produk')->result();
			
	$output = '';
	if(count($category) > 0 ):
		foreach($category as $row):
			if($row->kat_level == 3):
				if($selected):
					if($row->kategori_id == $selected):
						$output .= '<option value="'.$row->kategori_id.'" selected="selected">';
						$output .= $row->nama_kategori;
						$output .= '</option>';
					else:
						$output .= '<option value="'.$row->kategori_id.'">';
						$output .= $row->nama_kategori;
						$output .= '</option>';
					endif;
				else:
					$output .= '<option value="'.$row->kategori_id.'">';
					$output .= $row->nama_kategori;
					$output .= '</option>';
				endif;
			else:
				if($selected):
					$output .= '<optgroup label="'.str_repeat('&nbsp;&nbsp;',$row->kat_level-1).$row->nama_kategori.'">';
					$output .= produk_category_dropdown($row->brand_id, $row->kategori_id, $selected);
					$output .= '</optgroup>';
				else:
					$output .= '<optgroup label="'.str_repeat('&nbsp;&nbsp;',$row->kat_level-1).$row->nama_kategori.'">';
					$output .= produk_category_dropdown($row->brand_id, $row->kategori_id);
					$output .= '</optgroup>';
				endif;
			endif;
		endforeach;
	endif;
	return $output;
}

function get_image_produk($product_id)
{
	$ci=& get_instance();
	$ci->load->database();
	$output = '';
	$res = $ci->db->where('produk_id',$product_id)
		->get('tb_image_produk')
		->row();
	if($res):
		$output .= base_url().'public/product/'.$res->produk_img_thumb;
	endif;
	return $output;
}

function get_stok_produk($product_id,$ms_size_id=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();
	$output = 0;
	if($ms_size_id):
		$ci->db->where('ms_size_id', $ms_size_id);
	endif;
	$res = $ci->db->select_sum('jml_item')
		->where('produk_id',$product_id)
		->get('tb_size_produk')
		->row();
	if(count($res)>0):
		$output = $res->jml_item;
	endif;
	return $output;
}

function produk_size_list($produk_id=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();
	
	$output = "";
	$results = $ci->db->get('tb_ms_size')->result();
	foreach($results as $result):
		if($produk_id!=""):
			$produk_size = $ci->db->where('produk_id',$produk_id)
							->where('ms_size_id ',$result->ms_size_id)
							->get('tb_size_produk')->row();
			if(count($produk_size)>0):
				$output .= '<span class="size-label">'.$result->kode_size.' : </span><input type="text" size="2" class="size-input" name="size_'.$result->ms_size_id.'" value="'.$produk_size->jml_item.'"><span class="size-desc">('.$result->nm_size.')</span>';
			else:
				$output .= '<span class="size-label">'.$result->kode_size.' : </span><input type="text" size="2" class="size-input" name="size_'.$result->ms_size_id.'" value="0"><span class="size-desc">('.$result->nm_size.')</span>';
			endif;
		else:
			$output .= '<span class="size-label">'.$result->kode_size.' : </span><input type="text" size="2" class="size-input" name="size_'.$result->ms_size_id.'" value="0"><span class="size-desc">('.$result->nm_size.')</span>';
		endif;
		$output .= '<div style="clear:both;"></div>';
	endforeach;
	return $output;
}

function get_produk_image($produk_id,$look)
{
	$ci=& get_instance();
	$ci->load->database();
	
	$output = '';
	$result = $ci->db->where('produk_id',$produk_id)
				->where('look',$look)
				->get('tb_image_produk')
				->row();
	if(count($result)>0):
		$path = base_url().'public/product/'.$result->produk_img_thumb;
		if(file_exists(FCPATH.'public/product/'.$result->produk_img_thumb)):
			$output .= '<a href="" class="change-image-link" onclick="show_upload_box('.$produk_id.','.$look.');return false;">change image</a>';
			$output .= '<img src="'.$path.'" width="150">';
		else:
			$output .= '<a href="" class="change-image-link" onclick="show_upload_box('.$produk_id.','.$look.');return false;">upload new image</a>';
		endif;
	else:
		$output .= '<a href="" class="change-image-link" onclick="show_upload_box('.$produk_id.','.$look.');return false;">upload new image</a>';
	endif;
	return $output;
}

function get_brand_data($brand_id)
{
	$ci=& get_instance();
	$ci->load->database();
	
	return $ci->db->where('brand_id',$brand_id)->get('tb_brand')->row();
}

function get_kat_data($kategori_id)
{
	$ci=& get_instance();
	$ci->load->database();
	
	return $ci->db->where('kategori_id',$kategori_id)->get('tb_kat_produk')->row();
}

function get_order_data($order_id)
{
	$ci=& get_instance();
	$ci->load->database();
	
	return $ci->db->where('order_id',$order_id)->get('tb_order')->row();
}

function get_bank_data($bank_id)
{
	$ci=& get_instance();
	$ci->load->database();
	
	return $ci->db->where('bank_id',$bank_id)->get('tb_bank')->row();
}

function filter_brand($selected=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();
	
	$results = $ci->db->order_by('brand_id','asc')->get('tb_brand')->result();
	$output = "<select id='filter_brand' class='contact_input' name='filter_brand' style='width:200px;'>";
	($selected == 'all') ? $sel_all = ' selected="selected"' : $sel_all = '';
	$output .= '<option value="all"'.$sel_all.'>ALL</option>';
	foreach ($results as $result):
		($selected == $result->brand_id) ? $sel = ' selected="selected"' : $sel = '';
		$output .= '<option value="'.$result->brand_id.'"'.$sel.'>'.strtoupper($result->nama_brand).'</option> ';
	endforeach;
	$output .= '</select>';
	return $output;
}

function select_parent_category($kat_level,$brand_id,$selected=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();
	$output = '';
	if($selected==0):
		$selected = FALSE;
	endif;
	if($kat_level=='3'):
		$results = $ci->db->where('brand_id', $brand_id)
			->where('kat_level', '1')
			->get('tb_kat_produk')->result();
		if(count($results) > 0 ):
			foreach($results as $result):
				$results_2 = $ci->db->where('brand_id', $brand_id)
					->where('parent_kat_id',$result->kategori_id)
					->where('kat_level', '2')
					->get('tb_kat_produk')->result();
				$output .= '<optgroup label="'.$result->nama_kategori.'">';
				if(count($results_2) > 0 ):
					foreach($results_2 as $results_2):
					if($selected):
						if($results_2->kategori_id == $selected):
							$output .= '<option value="'.$results_2->kategori_id.'" selected="selected">';
							$output .= $results_2->nama_kategori;
							$output .= '</option>';
						else:
							$output .= '<option value="'.$results_2->kategori_id.'">';
							$output .= $results_2->nama_kategori;
							$output .= '</option>';
						endif;
					else:
						$output .= '<option value="'.$results_2->kategori_id.'">';
						$output .= $results_2->nama_kategori;
						$output .= '</option>';
					endif;
					endforeach;
				endif;
				$output .= '</optgroup>';
			endforeach;
		else:
			$results_2 = $ci->db->where('brand_id', $brand_id)
				->where('kat_level', '2')
				->get('tb_kat_produk')->result();
			if(count($results_2) > 0 ):
				foreach($results_2 as $results_2):
				if($selected):
					if($results_2->kategori_id == $selected):
						$output .= '<option value="'.$results_2->kategori_id.'" selected="selected">';
						$output .= $results_2->nama_kategori;
						$output .= '</option>';
					else:
						$output .= '<option value="'.$results_2->kategori_id.'">';
						$output .= $results_2->nama_kategori;
						$output .= '</option>';
					endif;
				else:
					$output .= '<option value="'.$results_2->kategori_id.'">';
					$output .= $results_2->nama_kategori;
					$output .= '</option>';
				endif;
				endforeach;
			else:
				$output .='<option value="0">No Parent</option>';
			endif;
		endif;
	elseif($kat_level=='2'):
		$results = $ci->db->where('brand_id', $brand_id)
			->where('kat_level', '1')
			->get('tb_kat_produk')->result();
		if(count($results) > 0 ):
			foreach($results as $result):
				if($selected):
					if($result->kategori_id == $selected):
						$output .= '<option value="'.$result->kategori_id.'" selected="selected">';
						$output .= $result->nama_kategori;
						$output .= '</option>';
					else:
						$output .= '<option value="'.$result->kategori_id.'">';
						$output .= $result->nama_kategori;
						$output .= '</option>';
					endif;
				else:
					$output .= '<option value="'.$result->kategori_id.'">';
					$output .= $result->nama_kategori;
					$output .= '</option>';
				endif;
			endforeach;
		else:
			$output .='<option value="0">No Parent</option>';
		endif;
	elseif($kat_level=='1'):
		$output .='<option value="0">No Parent</option>';
	endif;
	return $output;
}

function get_member_data($member_id,$return_data=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();
	
	$result = $ci->db->where('member_id',$member_id)->get('tb_member')->row();
	if(count($result)>0):
		if($return_data):
			return $result->$return_data;
		else:
			return $result;
		endif;
	else:
		return 'no data';
	endif;
}

function get_produk_data($produk_id,$return_data=FALSE)
{
	$ci=& get_instance();
	$ci->load->database();
	
	$result = $ci->db->where('produk_id',$produk_id)->get('tb_produk')->row();
	if(count($result)>0):
		if($return_data):
			return $result->$return_data;
		else:
			return $result;
		endif;
	else:
		return 'no data';
	endif;
}